package com.ynny.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Repository
public class AccountDaoImpl implements AccountDao{


    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int addAccount(String inAccount, BigDecimal money) {
        String sql = "update account set balance = balance + ? where cardId = ?";

        int i = jdbcTemplate.update(sql, money, inAccount);
        return i;
    }

    @Override
    public int subAccount(String outAccount, BigDecimal money) {
        String sql = "update account set balance = balance - ? where cardId = ?";

        int i = jdbcTemplate.update(sql, money, outAccount);
        return i;
    }
}
